/*
 * Copyright (c) 2009 Roman Savelyev
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef __TERMINALPROXY_H__
#define __TERMINALPROXY_H__

#include <conuiterminal.h>

NONSHARABLE_CLASS(CTerminalFailure) : public CBase
    {
public:
    CTerminalFailure(MConUiTerminalObserver& aObserver);
    TSize SurfaceSize();
    virtual void SetBackground(ConUiDef::TColor aColor);
    virtual void SetForeground(ConUiDef::TColor aColor);
    virtual void SetBold(TBool aBold);
    virtual void SetInverseVideo(TBool aInverseVideo);
    virtual void SetPos(const TPoint& aPoint);
    virtual void HideCursor();
    virtual void ShowCursor();
    virtual void Write(const TDesC& aOutput);
    virtual void ClearSurface();
    virtual void ReadKey(TConsoleKey& aKey, TRequestStatus& aStatus);
    virtual void ReadKeyCancel();
protected:
    MConUiTerminalObserver& iObserver;
    };

NONSHARABLE_CLASS(CTerminalProxy) : public CTerminalFailure, public MConUiTerminalObserver
    {
public:
    static CTerminalProxy* NewL(const TDesC8& aTerminalType, MConUiTerminalObserver& aObserver);
    ~CTerminalProxy();
     TSize SurfaceSize();
     void SetBackground(ConUiDef::TColor aColor);
     void SetForeground(ConUiDef::TColor aColor);
     void SetBold(TBool aBold);
     void SetInverseVideo(TBool aInverseVideo);
     void SetPos(const TPoint& aPoint);
     void HideCursor();
     void ShowCursor();
     void Write(const TDesC& aOutput);
     void ClearSurface();
     void ReadKey(TConsoleKey& aKey, TRequestStatus& aStatus);
     void ReadKeyCancel();
protected:
    CTerminalProxy(MConUiTerminalObserver& aObserver);
private:
    void ConstructL(const TDesC8& aTerminalType);
private:
    void HandleTerminalError(TInt aError);
    void Destroy();
private:
    CConUiTerminal* iTerminal;
    };

#endif /* __TERMINALPROXY_H__ */
